<template>
  <div>
    <headerWorld></headerWorld>
    <div class="header-swiper">
      <el-carousel
          style="width: 100%"
          :interval="4000"
          arrow="hover"
          height="450px"
          indicator-position="outside"
      >
        <el-carousel-item v-for="item in bannerList" :key="item">
          <img :src="item" alt class="swiperImage" />
        </el-carousel-item>
      </el-carousel>
    </div>
    <div class="content">
      <div class="main-content">
        <div
            class="course-section"
            v-for="couseContent in courseTitleList"
            :key="couseContent.categoryName"
        >
          <h2 class="section-title">{{ couseContent.categoryName }}</h2>
          <div class="course-grid">
            <div
                class="course-card"
                v-for="item in couseContent.courseList"
                :key="item.id"
                @click="goPage(item)"
            >
              <div class="course-image-wrapper">
                <img :src="item.image" alt class="course-image" />
                <span class="course-tag">{{ item.hasFree === 0 ? '免费' : '收费' }}</span>
                <div class="course-overlay"></div>
              </div>
              <div class="course-info">
                <div class="course-name">{{ item.name }}</div>
                <div class="course-teacher">主讲老师: {{ item.teacherName }}</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="sidebar">
      <div class="sidebar-section" @click="handleToDetail(7)">
        <div class="sidebar-icon"><i class="el-icon-info"></i></div>
        <div class="sidebar-text">关于我们</div>
      </div>
      <div class="sidebar-section" @click="handleToDetail(8)">
        <div class="sidebar-icon"><i class="el-icon-service"></i></div>
        <div class="sidebar-text">售后服务</div>
      </div>
      <div class="sidebar-section" @click="handleToDetail(9)">
        <div class="sidebar-icon"><i class="el-icon-warning"></i></div>
        <div class="sidebar-text">投诉建议</div>
      </div>
      <div class="sidebar-section" @click="handleToDetail(14)">
        <div class="sidebar-icon"><i class="el-icon-help"></i></div>
        <div class="sidebar-text">帮助中心</div>
      </div>
      <div class="sidebar-section">
        <div class="sidebar-icon"><i class="el-icon-mobile"></i></div>

        <img src="http://qiniu.pengfkt.com/FjF_4cnjhKgtIxOM97DYwvkii1KM" alt="公众号二维码" class="qr-code-image" />
        <div class="sidebar-text">公众号二维码</div>
      </div>
      <div class="sidebar-section">
        <div class="sidebar-icon"><i class="el-icon-phone"></i></div>
        <img src="http://qiniu.pengfkt.com/wxQrcode.png" alt="官方电话" class="qr-code-image" />

        <div class="sidebar-text">官方电话: {{ rightInfo.phone }}</div>
      </div>
    </div>
    <footWorld></footWorld>
  </div>
</template>

<script>
import { getBannerApi, getCourseApi, getRightInfo } from "@/common/api/index";
import footWorld from "@/components/footWorld";
import headerWorld from "@/components/headerWorld.vue";
export default {
  components: {
    footWorld,
    headerWorld,
  },
  data() {
    return {
      rightInfo: {},
      bannerList: [],
      courseTitleList: [],
    };
  },
  created() {
    this.getBannerList();
    this.getCourseList();
    this.getRightInfo();
  },
  methods: {
    goPage(item) {
      const path = item.hasFree === 0 ? `/freeLive/${item.id}` : `/homeIndex?id=${item.id}`;
      this.$router.push({ path });
    },
    handleToDetail(id) {
      this.$router.push({ path: "/article/detail", query: { id } });
    },
    async getBannerList() {
      const res = await getBannerApi({});
      this.bannerList = res.result.map((item) => item.image);
    },
    async getCourseList() {
      const res = await getCourseApi({});
      this.courseTitleList = res.result;
    },
    async getRightInfo() {
      const res = await getRightInfo();
      this.rightInfo = JSON.parse(res.result);
    },
  },
};
</script>

<style scoped lang="less">
.header-swiper {
  width: 100%;
  position: relative;
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中 */
  .swiperImage {
    width: 100%;
    height: 450px;
    object-fit: cover;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  }
}

.content {
  display: flex;
  justify-content: space-between;
  max-width: 1400px;
  margin: 80px auto;
  padding: 0 20px;
}

.main-content {
  flex: 1;
}

.course-section {
  margin-bottom: 60px;
  .section-title {
    font-size: 34px;
    color: #333;
    text-align: right;
    margin-right: 36px;
    margin-bottom: 30px;
    text-transform: uppercase;
    letter-spacing: 3px;
    position: relative;
    &::after {
      content: "";
      width: 100%;
      height: 4px;
      background: #FF6347; /* 替换原有的 #007aff */
      position: absolute;
      bottom: -10px;
      left: 0;
    }
  }
  .course-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 40px;
  }
  .course-card {
    flex: 1 1 calc(16.66% - 40px); /* 每行显示6个，宽度固定 */
    max-width: calc(16.66% - 40px); /* 保持每个卡片大小一致 */
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    transition: transform 0.4s ease, box-shadow 0.4s ease;
    cursor: pointer;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
    position: relative;
    &:hover {
      transform: translateY(-12px);
      box-shadow: 0 20px 30px rgba(0, 0, 0, 0.2);
    }
    .course-image-wrapper {
      position: relative;
      overflow: hidden;
      border-radius: 12px 12px 0 0;
      .course-image {
        width: 100%;
        height: 180px; /* 调整图片高度 */
        object-fit: cover;
        transition: transform 0.4s ease;
      }
      &:hover .course-image {
        transform: scale(1.1);
      }
      .course-overlay {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.4);
        opacity: 0;
        transition: opacity 0.4s ease;
      }
      &:hover .course-overlay {
        opacity: 1;
      }
      .course-tag {
        position: absolute;
        top: 12px;
        right: 12px;
        background: #FF6347; /* 替换原有的 #007aff */
        padding: 8px 12px;
        border-radius: 5px;
        color: #fff;
        font-size: 14px;
        font-weight: bold;
        z-index: 10;
      }
    }
    .course-info {
      padding: 20px;
      .course-name {
        font-size: 20px;
        color: #333;
        margin-bottom: 12px;
        font-weight: bold;
      }
      .course-teacher {
        font-size: 14px;
        color: #666;
      }
    }
  }

}

.sidebar {
  position: fixed;
  top: 100px;
  right: 40px;
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 25px;
}

.sidebar-section {
  display: flex;
  align-items: center;
  background: #f7f7f7;
  padding: 20px;
  border-radius: 15px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  transition: all 0.4s ease;
  &:hover {
    box-shadow: 0 12px 25px rgba(0, 0, 0, 0.2);
    background: #f0f0f0;
  }
  .sidebar-icon {
    font-size: 24px;
    color: #FF6347; /* 替换原有的 #007aff */
    margin-right: 15px;
  }
  .sidebar-text {
    font-size: 18px;
    color: #333;
    font-weight: bold;
  }
}

.qr-code-image {
  width: 80px;
  height: 80px;
  margin-right: 15px;
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

</style>
